﻿using NetWing.BPM.Admin.weixin;
using NetWing.Common;
using NetWing.Common.Data.SqlServer;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NetWing.BPM.Admin.JydModleOrder
{
    public partial class JydWapindex : System.Web.UI.Page
    {
        public int dw = 0;
        public int dww = 0;
        public int de = 0;
        protected string myopid;
        protected int sh = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //清楚cookie缓存
                //CookieHelper.ClearUserCookie("", "openid");
                myopid = CookieHelper.GetCookie("openid");
                if (!string.IsNullOrEmpty(myopid))
                {


                    string sql = ("select * from Sys_Users where openid='" + myopid + "'");

                    string sql1 = ("select * from jydUser where openid='" + myopid + "'");

                    DataTable dp = SqlEasy.ExecuteDataTable(sql);
                    DataTable op = SqlEasy.ExecuteDataTable(sql1);

                    if (dp == null || op == null)
                    {
                        Response.Redirect(ConfigHelper.GetValue("website") + "/weixin/bindyg.aspx");
                    }
                }
                else
                {
                    //当用户访问dingd.aspx 页面时,系统就会自动获得openid并返回当前页面
                    string reurl = Request.Url.ToString();//获取当前url
                    CookieHelper.WriteCookie("returnurl", reurl);//把返回信息写入cookies
                    bool r = wxhelper.checkLogin();//wxhelper.checkLogin() 该函数会自动去获得用户openid 获得openid后需要返回当前入口页面 reurl 就是获得openid后的入口页面
                    string kk = "";
                }



                string openidde = CookieHelper.GetCookie("openid");
                DataRow dr = SqlEasy.ExecuteDataRow("select tell from jydUser where OpenID='" + openidde + "' and tell<>''");
                sh = SqlEasy.ExecuteNonQuery("select * from Sys_Users where openid<>'' and IsAdmin = 1");   
                if (dr == null)
                {

                }
                else
                {
                    de = Convert.ToInt32(SqlEasy.ExecuteScalar("select COUNT(*) from jydOrder where tel='" + dr["tell"].ToString() + "'"));

                }

                //查询出cookie获取到的openID是否有和数据库中匹配的
                dw = Convert.ToInt32(SqlEasy.ExecuteScalar("select COUNT(*) from Sys_Users where openid='" + myopid + "'"));
                dww = Convert.ToInt32(SqlEasy.ExecuteScalar("select COUNT(*) from jydUser where openid='" + myopid + "'"));


            }
        }
    }
}